package com.ambulance.project.biz.mapper;

import com.ambulance.project.biz.dto.admin.ClassResourceDto;
import com.ambulance.project.biz.dto.admin.StaticItem;
import com.ambulance.project.biz.dto.web.ReportDto;
import com.ambulance.project.biz.dto.web.WebCarDto;
import com.ambulance.project.biz.entity.Doctor;
import com.ambulance.project.biz.entity.Nurse;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.util.List;

/***
 *  @description 自定义sql类
 *  @author zhao
 *  @date: 2020/4/21
 *  @version: v1.0
 */
@Repository
public interface MyCustomerMapper {


    @Select("select cl.*, doctor.name as doctorName,nurse.name as nurseName  from biz_class as cl  " +
            "left join biz_doctor as doctor on cl.doctorID = doctor.doctorID " +
            "left join biz_nurse as nurse on cl.nurseID = nurse.nurseID where 1 = 1 and cl.status=${status} and cl.carStatus=${carStatus}")
    List<ClassResourceDto> listClassResourceDto(@Param("status") Integer status, @Param("carStatus") Integer carStatus);


    @Select("select cl.*, doctor.name as doctorName,nurse.name as nurseName  from biz_class as cl  " +
            "left join biz_doctor as doctor on cl.doctorID = doctor.doctorID left join biz_nurse as nurse  on cl.nurseID = nurse.nurseID where 1 = 1 and cl.classID=${classID} ")
    ClassResourceDto infoClassResourceDto(@Param("classID") Integer classID);


    @Select("select uid from biz_user where token = #{token}")
    Integer selectUserIDByToken(@Param("token") String token);

    @Select("select * from biz_doctor where account=#{account}")
    Doctor selectDoctorByAccount(@Param("account") String account);

    @Select("select * from biz_nurse where account=#{account}")
    Nurse selectNurseByAccount(@Param("account") String account);

    @Select("select token from biz_user where uid =#{uid}")
    String selectTokenByUid(@Param("uid") Integer uid);

    @Select("select carID,vin,status,termSn,id,online,ultrasonicRoom,gatwayId  from  biz_car as c  where 1 =1 and c.uid=#{uid} and c.status != 3 and c.status != 1 order by c.status desc")
    List<WebCarDto> selectWebCarDtoByUid(@Param("uid") Integer uid);

    @Select("select carID,vin,status,termSn,id,online,ultrasonicRoom,gatwayId  from  biz_car as c  where 1 =1 and c.status != 3 and c.status != 1 order by c.status desc")
    List<WebCarDto> selectWebCarDtoByUid();

    @Select("select carID,vin,status,termSn,id,online  from  biz_car as c  where 1 =1 and c.carID=#{carID} order by c.status desc")
    WebCarDto selectWebCarDtoByCarID(@Param("carID") Integer carID);

    @Select("select uid ,count(1) as count from biz_dispatch where date(dispatch_time) = '${localDate}' group by uid")
    List<StaticItem> queryLastDayDispatcherNum(@Param("localDate")LocalDate localDate);

    @Select("select uid,sum(on_help_time) as count from biz_dispatch where date(dispatch_time) = '${localDate}' group by uid")
    List<StaticItem> queryLastDayOnHelpTime(@Param("localDate")LocalDate localDate);

    @Select("select uid,sum(on_car_time) as count from biz_dispatch  where date(dispatch_time) = '${localDate}' group by uid")
    List<StaticItem> queryLastDayOnCarTime(@Param("localDate")LocalDate localDate);

    @Select("select * from biz_report where dispathId = #{dispatchId}")
    ReportDto queryOneReport(@Param("dispatchId") Integer dispatchId);

}
